# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>

pkgname=flatpak-builder
pkgver=1.2.3
pkgrel=1
pkgdesc="Tool to build flatpaks from source"
url="https://flatpak.org"
arch=(x86_64)
license=(LGPL)
depends=(flatpak binutils elfutils unzip tar git bzr patch rpmextract cpio
         appstream-glib fuse3)
makedepends=(gobject-introspection git docbook-xsl xmlto)
checkdepends=(valgrind)
replaces=('flatpak<0.9.10')
_commit=d7dbc51267e83242a9fe0d5a7b5304db0ac72f4f  # tags/1.2.3
source=(
  "git+https://github.com/flatpak/flatpak-builder#commit=$_commit"
  "git+https://gitlab.gnome.org/GNOME/libglnx.git"
  "git+https://sourceware.org/git/debugedit.git"
  fusermount3.diff
)
sha256sums=('SKIP'
            'SKIP'
            'SKIP'
            '984ea70ac2c5794c758523aba9c1f643dc21fb01db4ed962987935a454d521a7')

pkgver() {
  cd $pkgname
  git describe --tags | sed 's/[^-]*-g/r&/;s/-/+/g'
}

prepare() {
  cd $pkgname

  # https://bugs.archlinux.org/task/75649
  git apply -3 ../fusermount3.diff

  git submodule init
  git submodule set-url libglnx "$srcdir/libglnx"
  git submodule set-url debugedit "$srcdir/debugedit"
  git -c protocol.file.allow=always submodule update

  NOCONFIGURE=1 ./autogen.sh
}

build() {
  cd $pkgname

  ./configure \
    --prefix=/usr \
    --sysconfdir=/etc \
    --localstatedir=/var \
    --sbindir=/usr/bin \
    --libexecdir=/usr/lib \
    --disable-static

  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool

  make
}

check() {
  cd $pkgname
  make -k check
}

package() {
  cd $pkgname
  make DESTDIR="$pkgdir" install
}

# vim:set sw=2 sts=-1 et:
